//
//  MoreViewController.m
//  Housekeeping
//
//  Created by 辰领科技 on 16/5/18.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "MoreViewController.h"
#import "UMSocial.h"
#import "SharePopView.h"

@interface MoreViewController ()<UIAlertViewDelegate>
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroView;
@property (strong, nonatomic) IBOutlet UIButton *contactInformationButton;//电话
@property (strong, nonatomic) IBOutlet UIButton *versionButton;//当前版本



@end

@implementation MoreViewController

- (void)viewWillAppear:(BOOL)animated{
    if (![Common getLoginStatus]) {
        
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    [self getPhoneNumber];
}



- (void)initViewLayout {
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    self.scroView.contentSize = flexibleSize(CGSizeMake(320, 504.5), YES);

    
}

#pragma mark  ==== 客服电话
- (void)getPhoneNumber {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_contactInformation withHttpType:@"POST" withTag:JY_JY_contactInformation ];
}

#pragma mark   === 拨号
- (IBAction)callHandel:(id)sender {
    [Common callPhone:_contactInformationButton.titleLabel.text view:self.view];
}

#pragma mark - 关于我们
- (IBAction)AboutUs:(id)sender {
    UIStoryboard *secondStroyBoard = [UIStoryboard storyboardWithName:@"PersonalStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"AboutUs"];
    [[Common getNavigation]pushViewController:page];
}
#pragma mark - 意见反馈
- (IBAction)feedback:(id)sender {
    UIStoryboard *secondStroyBoard = [UIStoryboard storyboardWithName:@"PersonalStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"feedback"];
    [[Common getNavigation]pushViewController:page];
}

#pragma mark - 检查更新
- (IBAction)update:(id)sender {
}

#pragma mark - 软件分享
- (IBAction)softwareShare:(id)sender {
//    UIStoryboard *secondStroyBoard = [UIStoryboard storyboardWithName:@"PersonalStoryboard" bundle:nil];
//    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"SoftwareShare"];
//    [[Common getNavigation]pushViewController:page];
    SharePopView * popView = [[SharePopView alloc]initWithTitles:@[@"微信好友",@"朋友圈",@"QQ空间",@"QQ好友"] complect:^(NSInteger index) {
        if (index == 0) {
            //微信好友
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:@"http://115.28.86.42:8083/edumap/portal/appDownload.do" image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
        } else if (index == 1) {
            //朋友圈
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:@"http://115.28.86.42:8083/edumap/portal/appDownload.do" image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
            
        } else if (index == 2) {
            //QQ空间
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQzone] content:@"http://115.28.86.42:8083/edumap/portal/appDownload.do" image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
        } else if (index == 3) {
            //QQ好友
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQQ] content:@"http://115.28.86.42:8083/edumap/portal/appDownload.do" image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
        }
        
    }];
    [popView show];
}

#pragma mark - 清除缓存
- (IBAction)ClearImageCache:(id)sender {
    CGFloat size = [[SDImageCache sharedImageCache]getSize];
    NSString * sizeStr = [NSString stringWithFormat:@"%.1fM",size /1000/1000];
    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"共%@图片缓存,确定清除？",sizeStr] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==1) {
        [[SDImageCache sharedImageCache]clearDisk];
    }
}

#pragma mark - 退出登录
- (IBAction)exitHandel:(id)sender {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[[Common getLoginInfo] objectForKey:Key_User_userId] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    self.shareApi.delegate=self;
//    [self.shareApi  requestOperationWithDic:dic withPath:KQ_exitLogin withHttpType:@"POST" withTag:KQ_KQ_exitLogin];
}


#pragma mark - 返回
- (IBAction)back:(id)sender {
    [self backBtn];
}



#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag == JY_JY_contactInformation){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
        }else  {

            [self.contactInformationButton setTitle:[NSString stringWithFormat:@"%@",database[@"result"]] forState:UIControlStateNormal];
        }
    }
//    else if (tag==KQ_KQ_exitLogin) {
//        
//        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
//            
//            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
//            
//        }else  {
//            [[CWHUDTips sharedInstance]  showTips:@"退出登录成功"  withStatus:2 dismissAfter:1.5];
//            [Common DeleteSingleFile];
//            [[AppDelegate sharedAppDelegate]  ShowLoginPage];
//            
//        }
//    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
